# ------------------------------------------------------------
# readListLex.py
# 
# Chase Miller
# CS 550 - Assignment 1.2a Lexer
#
# Largely inspired from examples from http://www.dabeaz.com/ply/ply.html#ply_nn2
#
# tokenizer for a simple expression evaluator for
# numbers, (, ), and ,
# ------------------------------------------------------------
import ply.lex as lex
import fileinput

# List of token names.   This is always required
tokens = (
   'NUMBER',
   'LPAREN',
   'RPAREN',
   'COMMA',
)

# Regular expression rules for simple tokens
t_LPAREN  = r'\('
t_RPAREN  = r'\)'
t_COMMA  = r','

# A regular expression rule with some action code
def t_NUMBER(t):
    r'\d+'
    t.value = int(t.value)    
    return t

# Define a rule so we can track line numbers
def t_newline(t):
    r'\n+'
    t.lexer.lineno += len(t.value)

# A string containing ignored characters (spaces, tabs, and newline characters)
t_ignore  = ' \t \n'

# Error handling rule
def t_error(t):
    print "-error-"
    exit()

# Build the lexer
lexer = lex.lex()